<?php
function admin_showerr( $_backname, $_backurl, $_backid)
{
				if ( $_backid== 0 )
				{
								$_backcontent= "操作失败";
								$_backpic= "<font style=\"font-size:30px; color: red;\">×</font>";
				}
				else
				{
								$_backcontent= "操作成功";
								$_backpic= "<font style=\"font-size:30px; color: green;\">√</font>";
				}
				echo "<table width=\"70%\" border=\"1\" align=\"center\" cellpadding=\"5\" cellspacing=\"0\" class=\"table\"><tr>";
				echo "<td colspan=\"2\"><strong>".$_backcontent."</strong></td>";
				echo "</tr><tr>";
				echo "<td width=\"25%\" height=\"100px\" align=center><strong>".$_backpic."</strong></td>";
				echo "<td width=\"75%\">".$_backname."<li><a href={$_backurl}>返回上一级</a></li></td>";
				echo "</tr></table><br />";
				exit( );
}
function backdatebase( )
{
    global $DB_Database;
    $DB_Database_Content= "#Powered by 028gc.com CMS 1.0 &copy; 2006-2009 028gc.com\r\n\r\n/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;\r\n/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;\r\n/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;\r\n\r\n/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;\r\n/*!40103 SET TIME_ZONE='SYSTEM' */;\r\n/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE */;\r\n/*!40101 SET SQL_MODE='' */;\r\n/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES */;\r\n/*!40103 SET SQL_NOTES='ON' */;\r\n\r\nset charset utf8;\r\n".( "DROP DATABASE IF EXISTS `".$DB_Database."`;\r\n" ).( "CREATE DATABASE `".$DB_Database."`;\r\n" ).( "USE `".$DB_Database."`;\r\n" );
    $DB_Database_tables= mysql_query( "show tables" );
    while ( $DB_Database_a= mysql_fetch_array( $DB_Database_tables) )
    {
        $DB_Database_b= $DB_Database_a[0];
        $DB_Database_c= mysql_query( "show create table`".$DB_Database_b."`" );
        $DB_Database_d= mysql_fetch_array( $DB_Database_c);
        $DB_Database_Content.= "#\r\n".( "#Dumping data for table `".$DB_Database_b."`" )."\r\n#\n\r\n\r\n";
        $DB_Database_Content.= $DB_Database_d['Create Table'].";\r\n\r\n/*!40101 SET NAMES utf8 */;\r\n";
        $DB_Database_q= mysql_query( "select * from`".$DB_Database_b."`" );
        while ( $DB_Database_f= mysql_fetch_assoc( $DB_Database_q) )
        {
            $DB_Database_k= array_keys( $DB_Database_f);
            $DB_Database_k= array_map( "addslashes", $DB_Database_k);
            $DB_Database_k= join( "`,`", $DB_Database_k);
            $DB_Database_k= "`".$DB_Database_k."`";
            $DB_Database_v= array_values( $DB_Database_f);
            $DB_Database_v= array_map( "addslashes", $DB_Database_v);
            $DB_Database_v= join( "','", $DB_Database_v);
            $DB_Database_v= "'".$DB_Database_v."'";
            $DB_Database_Content.= "insert into `".$DB_Database_b."`({$DB_Database_k}) values({$DB_Database_v});\r\n";
        }
    }
    $DB_Database_Content.= "\r\n\r\n/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;\r\n/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;\r\n/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;\r\n/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;\r\n/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;\r\n/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;\r\n";
    if ( function_exists( "date_default_timezone_set" ) )
    {
        date_default_timezone_set( "Hongkong" );
    }
    $DB_Database_file= "dbback/".date( "Ymd_H_i_s" ).".sql";
    wfile( $DB_Database_file, $DB_Database_Content);
}

function GetNextSQL()
{
    global $fp;
    $DB_Database_d= "";
    while ( $DB_Database_get= @fgets( $fp, 40960 ) )
    {
        $DB_Database_get= trim( $DB_Database_get);
        $DB_Database_get= str_replace( "\\\\", "\\", $DB_Database_get);
        $DB_Database_get= str_replace( "\\'", "''", $DB_Database_get);
        $DB_Database_get= str_replace( "\\r\\n", chr( 13 ).chr( 10 ), $DB_Database_get);
        $DB_Database_get= stripcslashes( $DB_Database_get);
        if ( 1 < strlen( $DB_Database_get) && $DB_Database_get[0] == "-" && $DB_Database_get[1] == "-" )
        {
            continue;
        }
        $DB_Database_d.= $DB_Database_get.chr( 13 ).chr( 10 );
        if ( !( 0 < strlen( $DB_Database_get) ) && !( $DB_Database_get[strlen( $DB_Database_get) - 1] == ";" ) )
        {
            continue;
        }
        break;
    }
    return $DB_Database_d;
}

function print_mysql_error( )
{
				echo "mysql_errno: ".mysql_errno( );
				echo "<br />";
				echo mysql_error( );
				@mysql_close( );
				exit( );
}

function addlog( $_logcontent, $_logname)
{
				global $db;
				if ( function_exists( "date_default_timezone_set" ) )
				{
								date_default_timezone_set( "Hongkong" );
				}
				@$_logtimeformat = @date( "Y-m-d H-i-s" );
				@$_obfuscate_NWGymn8 = @getenv( "SERVER_ADDR" );
				$db->query( "INSERT INTO tun2_log (logcontent,logtime,logoname,logip) VALUES \t\t('".$_logcontent."','{$_logtimeformat}','{$_logname}','".getip( )."')" );
}

function dafenglei_select($m,$id,$index)
{	
	global $class_arr;
	$n = str_pad('',$m,'-',STR_PAD_RIGHT);
	$n = str_replace("-","&nbsp;&nbsp;",$n);
	for($i=0;$i<count($class_arr);$i++){
	
		if($class_arr[$i][2]==$id){
			if($class_arr[$i][0]==$index){
				echo "        <option value=\"".$class_arr[$i][0]."\" selected=\"selected\">".$n."|--".$class_arr[$i][1]."</option>\n";
			}else{
				echo "        <option value=\"".$class_arr[$i][0]."\">".$n."|--".$class_arr[$i][1]."</option>\n";
			}
			dafenglei_select($m+1,$class_arr[$i][0],$index);
		}
	}
}
function work_back( $_workresults, $_workcontent)
{
				if ( empty( $_workresults ) )
				{
								$_workresults = "操作成功！正在返回......";
				}
				if ( empty( $_workcontent) )
				{
								$_workcontent= "javascript:history.back(1)";
				}
				echo "<table width=\"70%\" border=\"1\" align=\"center\" cellpadding=\"5\" cellspacing=\"0\" class=\"table\"><tr height=\"100px\"><td>";
				echo "<CENTER> ".$_workresults." </CENTER>";
				echo "</td></tr></table><br />";
				if ( $_workcontent!= "exit" )
				{
								echo "<meta http-equiv=refresh content=2;url=".$_workcontent.">";
								exit( );
				}
				exit( );
}



function login_check( )
{
    if ( $_SESSION['admin'] != "ok" )
    {
        session_unset( );
        session_destroy( );
        header( "Location: Admin_Login.php" );
        exit( );
    }
}
function echocolumns( $_columnstable, $_columnstr, $_columnstd)
{
				global $db1;
				$db1->query( "SELECT ".$_columnstr." FROM {$_columnstable} where id='{$_columnstd}'" );
				if ( $db1->next_record( ) )
				{
								echo $db1->Record[$_columnstr];
				}
}

function wfile( $_wfilea, $_wfileb, $_wfilec= "w" )
{
				$_wfiled = fopen( $_wfilea, $_wfilec);
				if ( !$_wfiled )
				{
								return false;
				}
				fwrite( $_wfiled, $_wfileb );
				fclose( $_wfiled );
				return true;
}

function getIP( )
{
				if ( getenv( "HTTP_CLIENT_IP" ) )
				{
								$_httpip = getenv( "HTTP_CLIENT_IP" );
								return $_httpip;
				}
				if ( getenv( "HTTP_X_FORWARDED_FOR" ) )
				{
								$_httpip = getenv( "HTTP_X_FORWARDED_FOR" );
								return $_httpip;
				}
				if ( getenv( "HTTP_X_FORWARDED" ) )
				{
								$_httpip = getenv( "HTTP_X_FORWARDED" );
								return $_httpip;
				}
				if ( getenv( "HTTP_FORWARDED_FOR" ) )
				{
								$_httpip = getenv( "HTTP_FORWARDED_FOR" );
								return $_httpip;
				}
				if ( getenv( "HTTP_FORWARDED" ) )
				{
								$_httpip = getenv( "HTTP_FORWARDED" );
								return $_httpip;
				}
				$_httpip = $_SERVER['REMOTE_ADDR'];
				return $_httpip;
}

function createFolder( $_createfoldername )
{
				if ( !file_exists( $_createfoldername ) )
				{
								createfolder( dirname( $_createfoldername ) );
								mkdir( $_createfoldername, 511 );
				}
}

function deldir( $_dirname)
{
				$_dirrun= opendir( $_dirname);
				while ( $_wfilea = readdir( $_dirrun) )
				{
								if ( !( $_wfilea != "." ) && !( $_wfilea != ".." ) )
								{
												$_dircontent= $_dirname."/".$_wfilea;
												if ( !is_dir( $_dircontent) )
												{
																unlink( $_dircontent);
												}
												else
												{
																deldir( $_dircontent);
												}
								}
				}
				closedir( $_dirrun);
				if ( rmdir( $_dirname) )
				{
								return true;
				}
				return false;
}

function delindexhtml( $_columnstd, $_indexname)
{
				global $db;
				$_indexsql= "SELECT webhtmlmode FROM tun2_config WHERE id =".$_columnstd;
				$db->query( $_indexsql);
				if ( $db->next_record() && $db->Record['webhtmlmode'] != $_indexname && $db->Record['webhtmlmode'] != "php" )
				{
								@unlink( "../index.".$db->Record['webhtmlmode'] );
				}
}

function toNum( $p )
{
				$p = trim( str_replace( ".", "", $p ) );
				if ( $p != "" )
				{
								return $p;
				}
}

define( "COPY", "<font style=\"font-family:Arial, Helvetica, sans-serif; font-size:10px;\">Powered by 泸州北方化学工业有限公司 <strong>028gc.com cms 1.0 </strong>&copy; 2006-2009 <a href=\"http://www.028gc.com\" target=\"_blank\"><strong><font color=\"#ff3300\">028gc</font>.com</strong></a></font>" );
?>
